#!/bin/bash
# Copyright (C) 2015 Yaowen HE
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

log_file="install.log"

# display help information
# usage: display_help
display_help () {
    echo "usage: uninstall.sh [--prefix=PREFIX] [--help]"
    echo
    echo "  --prefix=PREFIX  prefix installed"
    echo "  --help           show help and exit"

    exit $1
}

source src/functions.sh

if has_opt "help" "$@"; then
    display_help
    exit
fi

prefix=$(eval echo $(get_opt "prefix" "$@"))


if [ -z "$prefix" ]; then
    if [ -r $log_file ]; then
        prefix=$(grep "Start installation to" $log_file | tail -n1 | sed 's/.*Start installation to "\(.*\)"/\1/')
    else
        echo "'$logfile' not found, use '--prefix'" >&2
    fi
fi

rm -rf "$prefix"/share/fmark
rm "$prefix"/bin/fmark
rm "$prefix"/etc/fmark.conf*
